package com.panfeng.xcloud.common.core.web.vo;

import com.panfeng.xcloud.common.core.enums.ResponseStatusEnum;

/**
 *
 * 响应工具类
 *
 * @author xiaobo
 * @version 1.0
 * @since 2017-04-10
 */
public class ResponseUtils {

	/**
	 * 根据状态获取相应的响应实体
	 *
	 * @param responseStatusEnum
	 * @return
	 */
	public static <T> ResponseVO<T> getResponseByStatus(ResponseStatusEnum responseStatusEnum) {
		ResponseVO<T> responseVO = new ResponseVO<T>();
		if (responseStatusEnum != null) {
			responseVO.setMessage(responseStatusEnum.getMessage());
			responseVO.setCode(responseStatusEnum.getCode());
		}
		return responseVO;
	}

	/**
	 * 设置对应状态码
	 *
	 * @param responseStatusEnum
	 * @return
	 */
	public static <T> void setResponseStatus(ResponseVO<T> responseVO, ResponseStatusEnum responseStatusEnum) {
		if (responseStatusEnum != null) {
			responseVO.setMessage(responseStatusEnum.getMessage());
			responseVO.setCode(responseStatusEnum.getCode());
		}
	}
}
